package com.handinfo.uimenu.window;

import javax.microedition.lcdui.Graphics;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.game.ActorItem;
import com.handinfo.game.GameScene;
import com.handinfo.util.Tools;

public class ShowData
{
	private int m_size;
	private byte[] m_type;//类型 1纯字 2纯字(道具名称)+数字 3图（道具图标）x数字
	private int[] m_colour;
	private int[] m_colourw;
	private String[] m_info;
	private int[] m_iconID;
	private int[] m_x,m_y;
	private final int m_srch = 5;
	private final int m_line;
	public boolean m_life;
	private int m_move;
	private int m_startX,m_startY;
	public int m_clipX,m_clipY;
	private final int m_speed = 4;
	

	public ShowData(int size,int X,int Y,int Line)
	{
	  m_size = size;
	  m_startX = X;
	  m_startY = Y;
	  m_line = Line;
	  m_clipX = 0;
	  m_clipY = Y - m_line;
      m_type = new byte[size];
      m_colour = new int[size];
      m_colourw = new int[size];
      m_info = new String[size];
      m_iconID = new int[size];
      m_x = new int[size];
      m_y = new int[size];
      m_move = 0;
      m_life = false;
	}
	
	public ShowData init(int index,byte type,int colour,int colourw,String info,int num){
		if(index < 0 || index > m_size){
			return null;
		}
		m_type[index] = type;
		m_colour[index] = colour;
		m_colourw[index] = colourw;
		m_x[index] = m_startX;
		m_y[index] = m_startY + index * (m_srch+AbstractGameScreen.FONT_H);
		switch(type){
			case 0://1纯字
				m_info[index] = info;
				break;
			case 1://2纯字(道具名称)+数字
				m_info[index] = info.concat(" + ").concat(""+num);
				break;
			case 2://图（道具图标）x数字
				m_iconID[index] = Integer.parseInt(info);
				m_info[index] = " X "+num;
				break;
		}
		return this;
	}
	
	public void draw(Graphics g){
		if( m_size < 0 || m_info == null || m_info.length != m_size){
			return;
		}
		for(int i=0;i<m_size;i++){
			if( m_info[i] == null ){
				return;
			}
			switch(m_type[i]){
				case 0:
				case 1:
					Tools.drawString(g, m_colour[i], m_colourw[i], m_info[i], m_x[i], m_y[i] - m_move, 0);
					break;
				case 2:
					ActorItem.drawIcon(g, m_x[i], m_y[i]- m_move, 0, 0, m_iconID[i], 0, 0, false);
					Tools.drawString(g, m_colour[i], m_colourw[i], m_info[i], m_x[i]+GameScene.SIZE_IMG_ICON[1], m_y[i]- m_move, 0);
					break;
			}	
		}
		
	}
	
	public void run(){
		if( m_y[m_size-1]+AbstractGameScreen.FONT_H - m_move < m_y[0] - m_line){
			m_life = true;
		}else{
			m_move+=m_speed;
		}
	}
}
